package adapter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import uimain.PrivateNotes;

import com.actionbarsherlock.app.SherlockActivity;
import com.adgroup.smartnote.AcceptActivity;
import com.adgroup.smartnote.AddMemberToGroupActivity;
import com.adgroup.smartnote.CreateGroupActivity;
import com.adgroup.smartnote.LoginActivity;
import com.adgroup.smartnote.R;
import com.adgroup.smartnote.RegisterActivity;
import com.adgroup.smartnote.SearchFriend;
import com.adgroup.smartnote.SmartNoteActivity;
import com.androidquery.AQuery;
import com.fortysevendeg.swipelistview.SwipeListView;

import database.Database;

import JsonModel.Group;
import JsonModel.User;
import Net.JsonParse;
import Utilities.Configuration;
import Utilities.Utility;
import ViewFragment.AcceptFriendActivity;
import adapter.AdapterCategories.Holder;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import animationmenu.CollapseAnimation;
import animationmenu.ExpandAnimation;

public class AdapterAllGroup {
	ArrayList<Group> arr;
	PrivateNotes c;
	public AdapterAllGroup(PrivateNotes context, ArrayList<Group> arr)
	{
		this.c = context;
		this.arr = arr;
	}
	public class Holder
	{
		ImageView iv;
		TextView tvTitle;
		TextView tvCat, tvNumNews;
		ImageButton btn;
		LinearLayout root;
	}
	public class Adapter extends BaseAdapter 
	{

		@Override
		public int getCount() {
			return arr.size();
		}

		@Override
		public Object getItem(int arg0) {
			return arr.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}
		public void setArrayGroup(ArrayList<Group> a){
			arr = a;
		}
		@Override
		public View getView(final int arg0, View arg1, ViewGroup arg2) {
			Holder holder;
			LayoutInflater inflater = c.getSherlockActivity().getLayoutInflater();
			if (arg1 == null) {
				holder = new Holder();
				arg1 = inflater.inflate(R.layout.itemallgroup,arg2, false);
				holder.tvCat = (TextView) arg1
						.findViewById(R.id.textViewCategoryGroup);
				holder.iv = (ImageView) arg1
						.findViewById(R.id.imageViewLogoGroup);	
				holder.tvTitle = (TextView) arg1.findViewById(R.id.textViewTitleGroup);
				holder.tvNumNews = (TextView) arg1.findViewById(R.id.textViewTotalNews);
				holder.btn = (ImageButton) arg1.findViewById(R.id.imageButtonMoreGroup);
				holder.root = (LinearLayout) arg1.findViewById(R.id.rootItemAllGroup);
				arg1.setTag(holder);
			} else {
				holder = (Holder) arg1.getTag();
			}
		//	((SwipeListView)arg1).recycle(arg1, arg0);
			//get model friend
			final Group f = arr.get(arg0);
			holder.tvCat.setText(f.getGroupCatName() +" (" +f.getTotal() +")");
			holder.tvNumNews.setText(f.getNumNews());
			holder.tvTitle.setText(f.getTitle());
			if(f.getNumNews().equalsIgnoreCase("0")){
				holder.tvNumNews.setVisibility(View.GONE);
			}
			AQuery aq = new AQuery(arg1);
			Bitmap placeholder = aq.getCachedImage(R.drawable.imageload);
			aq.id(holder.iv).image(arr.get(arg0).getLink(), true,
						true, 0, 0, placeholder, AQuery.FADE_IN_NETWORK, 1.0f);
			
			holder.btn.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					
				}
			});
			holder.root.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg) {
					((PrivateNotes)c).setOnClickItemListView(arr.get(arg0));
				}
			});
			return arg1; 
		}

		public void removeGroup(Group u) {
			arr.remove(u);
			this.notifyDataSetChanged();
		}
	
	}
	
}
